// pages/classify/classify.js
var util = require('../../utils/util.js');
var api = require('../../config/api.js');

Page({
  data: {
    navLeftItems: [],
    navRightItems: [],
    curNav: 19,
    curIndex: 0,
  },
  onLoad: function () {
    // console.log('begin')
    var that = this
    //console.log('begin' + api.producttype)

    util.request(api.producttype).then(function (res) {
      // if (res.errno === 0) {
      for (var index in res.data.data) {
        if (res.data.data[index].fldphotourl)
        {
        res.data.data[index].fldphotourl = api.apiimgurl + res.data.data[index].fldphotourl.split('|')[1];
      }}

      that.setData({
        navLeftItems: res.data.data.filter(it => it.fldparentid == 0),
        navRightItems: res.data.data.filter(it => it.fldparentid != 0)
      })


      //}

      // wx.request({
      //  // url: 'http://huanqiuxiaozhen.com/wemall/goodstype/typebrandList',
      //   url:'http://f10.ylwxmall.com:6035/shopping/api/producttype/get_listcategory',
      //   method: 'GET',
      //   data: {},
      //   header: {
      //     'Accept': 'application/json'
      //   },
      //   success: function (res) {
      //     console.log(res)
      //     that.setData({
      //       navLeftItems: res.data.data.filter(it => it.fldparentid == 0),
      //       navRightItems: res.data.data.filter(it => it.fldparentid != 0)
      //     })
      //   }
    })

  },

  //事件处理函数
  switchRightTab: function (e) {
    // 获取item项的id，和数组的下标值
    let id = e.target.dataset.id,
      index = parseInt(e.target.dataset.index);
    // 把点击到的某一项，设为当前index
    this.setData({
      curNav: id,
      curIndex: index
    })
  }

})